﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Shove.Web.UI;

public partial class UserControls_EditPassword : UCBase 
{
    public UserControls_EditPassword()
    {
        Name = "修改密码";

        swpas = new ShoveWebPartAttribute[17];

        swpas[0] = new ShoveWebPartAttribute_Int("控件宽度", "1,1004", 759, "控件宽度");
        swpas[1] = new ShoveWebPartAttribute_Int("导航单元格高度", "1,500", 23, "导航单元格高度");
        swpas[2] = new ShoveWebPartAttribute_Int("导航单元格宽度", "1,600", 139, "导航单元格宽度");
        swpas[3] = new ShoveWebPartAttribute_Int("标题行高", "1,200", 23, "标题行高");
        swpas[4] = new ShoveWebPartAttribute_Int("待用", "1,100", 98, "标题单元格百分比");

        swpas[5] = new ShoveWebPartAttribute_Color("控件边框颜色", "#E7C890", "控件边框颜色");
        swpas[6] = new ShoveWebPartAttribute_Image("取消按钮图片", "", "images/UserControls/button_qx.jpg", "取消按钮图片");
        swpas[7] = new ShoveWebPartAttribute_Image("导航背景图片1", "", "images/UserControls/bg_gold_23.jpg", "导航背景图片1");
        swpas[8] = new ShoveWebPartAttribute_Image("导航背景图片2", "", "images/UserControls/bg_gold_23_2.jpg", "导航背景图片2");

        swpas[9] = new ShoveWebPartAttribute_Text("导航文本样式", "", "black12", "导航文本样式");

        swpas[10] = new ShoveWebPartAttribute_Int("行高", "1,500", 26, "行高");
        swpas[11] = new ShoveWebPartAttribute_Int("文本框宽度", "1,500", 178, "文本框宽度");
        swpas[12] = new ShoveWebPartAttribute_Int("提示标题宽度百分比", "1,100", 20, "提示标题宽度百分比");

        swpas[13] = new ShoveWebPartAttribute_Text("提示标题样式", "", "black12", "提示标题样式");
        swpas[14] = new ShoveWebPartAttribute_Text("文本框样式", "", "in_p2", "文本框样式");
        swpas[15] = new ShoveWebPartAttribute_Text("验证信息样式", "", "help12", "验证信息样式");

        swpas[16] = new ShoveWebPartAttribute_Image("确定按钮图片", "", "images/UserControls/button_ok.jpg", "确定按钮图片");      
    }

    private void Initlayout()
    {
        //tabctr.Width = swpAttributes[0];
        //tabctr.BgColor = swpAttributes[5];

        //tdsign.Width = swpAttributes[2];
        //tdsign.Height = swpAttributes[1];
        //tdsign.Style.Add("background-image", "url('" + swpAttributes[7] + "')");
        //tdsign.Attributes.Add("class", swpAttributes[9]);

        //tdspace.Style.Add("background-image", "url('" + swpAttributes[8] + "')");

        tdtitle.Height = swpAttributes[10];
        tdtitle.Attributes.Add("class", swpAttributes[13]);
        tdtitle.Width = swpAttributes[12] + "%";
        tdtitle1.Attributes.Add("class", swpAttributes[15]);
        txtOldPwd1.CssClass = swpAttributes[14];
        txtOldPwd1.Width = new Unit(swpAttributes[11]);

        tdfrist.Height = swpAttributes[10];
        tdfrist.Attributes.Add("class", swpAttributes[13]);
        tdfrist.Width = swpAttributes[12] + "%";
        tdfrist1.Attributes.Add("class", swpAttributes[15]);
        txtNewPwd1.CssClass = swpAttributes[14];
        txtNewPwd1.Width = new Unit(swpAttributes[11]);

        tdre.Height = swpAttributes[10];
        tdre.Attributes.Add("class", swpAttributes[13]);
        tdre.Width = swpAttributes[12] + "%";
        tdre1.Attributes.Add("class", swpAttributes[15]);
        txtPwd1.CssClass = swpAttributes[14];
        txtPwd1.Width = new Unit(swpAttributes[11]);

        tdsecond.Height = swpAttributes[10];
        tdsecond.Attributes.Add("class", swpAttributes[13]);
        tdsecond.Width = swpAttributes[12] + "%";
        tdsecond1.Attributes.Add("class", swpAttributes[15]);
        txtNewPwd2.CssClass = swpAttributes[14];
        txtNewPwd2.Width = new Unit(swpAttributes[11]);

        tdrepsw.Height = swpAttributes[10];
        tdrepsw.Attributes.Add("class", swpAttributes[13]);
        tdrepsw.Width = swpAttributes[12] + "%";
        tdrepsw1.Attributes.Add("class", swpAttributes[15]);
        txtPwd2.CssClass = swpAttributes[14];
        txtPwd2.Width = new Unit(swpAttributes[11]);

        ibOK.ImageUrl = "~/" + swpAttributes[16];
        ibCancel.ImageUrl = "~/" + swpAttributes[6];
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (_Customer == null)
        {
            Response.Redirect("Default.aspx?PN=Login");
        }

        Initlayout();
     }
   
    /// <summary>
    /// 确定修改
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void ibOK_Click(object sender, ImageClickEventArgs e)
    {
        if (PublicFunction.EncryptPassword(txtOldPwd1.Text) != _Customer.Password1)
        {
            Shove._Web.JavaScript.Alert(this.Page, "原一级密码错误！");

            return;
        }

        DAL.Tables.tbl_Customer Customer = new DAL.Tables.tbl_Customer();
        Customer.Password1.Value = PublicFunction.EncryptPassword(txtNewPwd1.Text);
        Customer.Password2.Value = PublicFunction.EncryptPassword(txtNewPwd2.Text);
        Customer.Update("ID ="+_Customer.ID);

        Shove._Web.JavaScript.Alert(this.Page, "修改成功！");
    }

    /// <summary>
    /// 取消修改
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void ibCancel_Click(object sender, ImageClickEventArgs e)
    {
        Response.Redirect("Default.aspx?PN=member_home");
    }
}
